package com.xyq.friend.controller.user;

import com.xyq.common.core.constants.HttpConstants;
import com.xyq.common.core.controller.BaseController;
import com.xyq.common.core.domain.Result;
import com.xyq.friend.aspect.CheckStatus;
import com.xyq.friend.domain.user.dto.UserAddDTO;
import com.xyq.friend.domain.user.dto.UserLoginDTO;
import com.xyq.friend.domain.user.dto.UserUpdateDTO;
import com.xyq.friend.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
    @Autowired
    private UserService userService ;

    @PostMapping("/register")
    public Result<String> register(@RequestBody @Validated UserAddDTO userAddDTO){
        return userService.register(userAddDTO);
    }
    @PostMapping("/login")
    public Result login(@RequestBody @Validated UserLoginDTO userLoginDTO){
        return userService.login(userLoginDTO) ;
    }

    @DeleteMapping("/logout")
    public Result logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toResult( userService.logout(token) );
    }
    @CheckStatus
//  获取用户个人信息
    @GetMapping("/info")    // 获取响应中的header里的值
    public Result info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return userService.info(token);
    }
    @CheckStatus
    @GetMapping("/detail")
    public Result detail(){
       return Result.success(userService.detail());
    }
    @CheckStatus

    @PutMapping("/edit")
    public Result edit(@RequestBody UserUpdateDTO userUpdateDTO){
        return toResult(userService.edit(userUpdateDTO));
    }
    @CheckStatus

    @PutMapping("/head-image/update")
    public Result updateHeadImage(@RequestBody UserUpdateDTO userUpdateDTO){
        return toResult(userService.updateHeadImage(userUpdateDTO));
    }
}
